#ifndef __CONVERT_H__
#define __CONVERT_H__

#include "math/math_config.h"
#include "math/math_def.h"
#include <sstream>


NS_MATH_BEGIN

template<typename T>
std::string num2str(const T& val, const std::string& formatstr = "")
{
	std::string str;
	if(formatstr.empty())
	{
		std::stringstream ss;
		ss<<val;
		ss>>str;
		return str;
	}else
	{
		char buffer[100];
		sprintf_s<100>(buffer, formatstr.c_str(), val);
		str = std::string(buffer);
		return str;
	}
}

template<typename T>
std::string num2str(const complex<T>& val, const std::string& formatstr)
{
	std::string r_str, i_str, str;
	r_str = num2str(val.real, "%g");
	i_str = num2str(val.imag, "%+g");

	str = r_str;
	str += i_str;
	str += " i";

	return str;
}




NS_MATH_END


#endif